<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">

    <ui:define name="title">菜单管理</ui:define>
    <ui:define name="content">
        <h:form>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="right">
                        <p:commandButton value="禁用"
                                         icon="fa fa-warning"
                                         actionListener="#{menuBean.onDisableMenu}"
                                         update="@form"
                                         rendered="#{menuBean.$ != null and menuBean.$.enable and  security:areAllGranted('MENU_DISABLE') and menuBean.isView()}">
                            <p:confirm header="提示信息" message="禁用节点将一并禁用其下子节点,是否确定禁用?" icon="ui-icon-alert"/>
                        </p:commandButton>
                        <p:commandButton value="启用"
                                         icon="fa fa-play"
                                         actionListener="#{menuBean.onEnableMenu}"
                                         update="@form"
                                         rendered="#{menuBean.$ != null and !menuBean.$.enable and security:areAllGranted('MENU_ENABLE') and menuBean.isView()}"/>
                        <p:commandButton value="删除"
                                         icon="fa fa-remove"
                                         actionListener="#{menuBean.onDeleteMenu}"
                                         update="@form"
                                         rendered="#{menuBean.$ != null and menuBean.isView()}">
                            <p:confirm header="提示信息" message="删除节点将一并删除其下子节点,是否确定删除?" icon="ui-icon-alert"/>
                        </p:commandButton>
                        <p:commandButton value="编辑"
                                         icon="fa fa-edit"
                                         actionListener="#{menuBean.changeStatusToEdit}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{menuBean.$ != null and menuBean.isView() and security:areAllGranted('MENU_EDIT')}"/>
                        <p:commandButton value="保存"
                                         icon="fa fa-save"
                                         actionListener="#{menuBean.onSaveMenu}"
                                         update="@form"
                                         rendered="#{menuBean.$ != null and menuBean.isNotView() and security:areAnyGranted('MENU_EDIT,MENU_ADD')}"/>
                        <p:commandButton value="取消" icon="fa fa-reply"
                                         actionListener="#{menuBean.onCancel}"
                                         rendered="#{menuBean.isNotView()}"
                                         process="@this"
                                         update="@form"/>
                        <p:commandButton value="新增"
                                         icon="fa fa-plus"
                                         actionListener="#{menuBean.onAddMenu}"
                                         update="@form"
                                         rendered="#{menuBean.selectedNode != null and menuBean.isView() and security:areAllGranted('MENU_ADD')}"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">

                <div class="ui-g-4">
                    <div class="card">
                        <h1>菜单</h1>
                        <p:tree value="#{menuBean.root}" var="node" dynamic="true"
                                selectionMode="single" selection="#{menuBean.selectedNode}" animate="true"
                                expanded="true" draggable="true" droppable="true"
                                rendered="#{security:areAllGranted('MENU_SEARCH')}"
                                filterBy="#{node.name}"
                                filterMatchMode="contains">

                            <p:ajax event="select" update="@form" listener="#{menuBean.onSelectNode}"/>
                            <p:ajax event="dragdrop" listener="#{menuBean.onMoveMenu}" update="@form"/>

                            <p:treeNode icon="#{node.icon}">
                                <h:outputText value="#{node.title}(启用)" rendered="#{node.enable}"/>
                                <h:outputText value="#{node.title}(禁用)" style="color: red" rendered="#{!node.enable}"/>
                            </p:treeNode>
                        </p:tree>
                    </div>
                </div>
                <h:panelGroup rendered="#{menuBean.$ != null}">
                    <div class="ui-g-8">
                        <div class="card">
                            <h1>菜单信息</h1>
                            <p:panelGrid columns="2"
                                         columnClasses="ui-grid-col-2,ui-grid-col-10"
                                         layout="grid" styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">

                                <p:outputLabel for="title" value="菜单标题"/>
                                <p:inputText id="title" value="#{menuBean.$.title}" disabled="#{menuBean.isView()}"/>

                                <p:outputLabel for="code" value="菜单编码"/>
                                <p:inputText id="code" value="#{menuBean.$.code}" disabled="#{menuBean.isView()}"/>

                                <p:outputLabel for="sort" value="菜单排序"/>
                                <p:spinner id="sort" value="#{menuBean.$.sort}" disabled="#{menuBean.isView()}"/>

                                <p:outputLabel for="permissionCode" value="权限编码"/>
                                <p:inputText id="permissionCode" value="#{menuBean.$.permissionCode}"
                                             disabled="#{menuBean.isView()}"/>

                                <p:outputLabel for="icon" value="图标"/>
                                <p:inputText id="icon" value="#{menuBean.$.icon}" disabled="#{menuBean.isView()}"/>

                                <p:outputLabel for="remark" value="备注"/>
                                <p:inputTextarea id="remark"
                                                 value="#{menuBean.$.remark}" disabled="#{menuBean.isView()}"/>

                                <p:outputLabel for="enable" value="是否启用"/>
                                <p:inputSwitch id="enable" onLabel="是" offLabel="否"
                                               value="#{menuBean.$.enable}" disabled="#{menuBean.isView()}"/>

                                <p:outputLabel for="leaf" value="是否叶子节点"/>
                                <p:inputSwitch id="leaf" onLabel="是" offLabel="否" value="#{menuBean.$.leaf}"
                                               disabled="#{menuBean.isView()}">
                                    <p:ajax event="change" process="@form" update="@form"/>
                                </p:inputSwitch>

                                <p:outputLabel for="url" value="URL" rendered="#{menuBean.$.leaf}"/>
                                <p:inputText id="url" value="#{menuBean.$.url}" rendered="#{menuBean.$.leaf}"
                                             disabled="#{menuBean.isView()}"/>

                            </p:panelGrid>
                        </div>
                    </div>
                </h:panelGroup>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
